package xjh.him.util;

import android.util.Log;

public class LogcatUtil {
    private static final String TAG = "com.xjh.him";
    private static final boolean LOG_ENABLE = true;

    // debug
    public static void d(String format, Object... msg){
        if (LOG_ENABLE){
            Log.d(TAG, makeLog(format, msg));
        }
    }


    // info
    public static void i(String format, Object... msg){
        if (LOG_ENABLE){
            Log.i(TAG, makeLog(format, msg));
        }
    }

    // warn
    public static void w(String format, Object... msg){
        if (LOG_ENABLE){
            Log.w(TAG, makeLog(format, msg));
        }
    }

    private static String makeLog(String format, Object... msg) {
        StringBuilder builder = new StringBuilder();
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        builder.append(stackTrace[4].getClassName())
                .append('.')
                .append(stackTrace[4].getMethodName())
                .append(':')
                .append(stackTrace[4].getLineNumber())
                .append(' ')
                .append(String.format(format, msg));
        return builder.toString();
    }
}
